package net.araim.bbingo.activity;

import net.araim.bbingo.R;
import net.araim.bbingo.Settings;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ToggleButton;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class SettingsScreen extends Activity {

	private Settings settings;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settingsscreenlayout);

		settings = Settings.getInstance(getApplicationContext());
		View v = findViewById(R.id.SettingsRadioGroup1);

		RadioGroup rg = (RadioGroup) v;
		rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(RadioGroup group, int checkedId) {
				RadioButton rb = (RadioButton) findViewById(checkedId);

				if (rb.getId() == R.id.RadioButton01) {
					settings.setSize(4);
				} else if (rb.getId() == R.id.RadioButton02) {
					settings.setSize(5);
				} else if (rb.getId() == R.id.RadioButton03) {
					settings.setSize(6);
				}
			}
		});

		int size = settings.getSize();
		if (size == 4) {
			((RadioButton) findViewById(R.id.RadioButton01)).setChecked(true);
		} else if (size == 5) {
			((RadioButton) findViewById(R.id.RadioButton02)).setChecked(true);
		} else if (size == 6) {
			((RadioButton) findViewById(R.id.RadioButton03)).setChecked(true);
		}

		Button b = ((Button) findViewById(R.id.SaveSettingsButton));
		b.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});

		ToggleButton tb = (ToggleButton) findViewById(R.id.SoundToggle);
		tb.setChecked(settings.isSoundOn());
		tb.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				settings.setSound(((ToggleButton) v).isChecked());
			}
		});

		Button editTexts = (Button) findViewById(R.id.EditTexts);
		editTexts.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent i = new Intent(getApplicationContext(), EditTextsActivity.class);
				startActivity(i);
			}
		});

	}

}
